// Dict.js

import Vue from 'vue'
// 引入自己获取字典的接口
import { getTypeDictType } from '@/api/dict'

export default class Dict {
  constructor(dict) {
    this.dict = dict
    console.log('this.dict: ', this.dict)
  }

  async init(names, completeCallback) {
    if (names === undefined || name === null) {
      throw new Error('need Dict names')
    }
    const ps = []
    names.forEach(n => {
      // 根据自己的需求可以自定义格式储存，一般只保留 Vue.set(this.dict, n, []) 就可以，下面与上面对应
      Vue.set(this.dict.type, n, {})
      ps.push(getTypeDictType(n).then(data => {
        data.data.data.forEach((d, index) => {
          const { value, type } = d
          d.value = type == 'Number' ? Number(value) : value
          Vue.set(this.dict.type[n], index, d)
          Vue.set(this.dict.pageSizes, index, d.value)
        })
      }))
    })
    await Promise.all(ps)
    completeCallback()
  }
}

